/*
 * @(#)AuthInterceptor.java 2009-3-25
 * Copyright (c) 2008-2015 by CJK
 * All rights reserved.
 */
package net.beyond.core.util;

import javax.annotation.Resource;

import net.beyond.common.auth.Authorization;
import net.beyond.common.struts2.ResultKeys;

import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

/**
 * 
 * @author Shmiluyu
 * @version 1.000 2009-3-25
 */
@Component("authInterceptor")
public class AuthInterceptor implements Interceptor {

	@Resource(name = "util.authorization")
	private Authorization authEngine;
	/** */
	private static final long serialVersionUID = 1L;

	/*
	 * @see com.opensymphony.xwork2.interceptor.Interceptor#destroy()
	 */
	public void destroy() {
	}

	/*
	 * @see com.opensymphony.xwork2.interceptor.Interceptor#init()
	 */
	public void init() {
	}

	/*
	 * @see
	 * com.opensymphony.xwork2.interceptor.Interceptor#intercept(com.opensymphony
	 * .xwork2.ActionInvocation)
	 */
	public String intercept(ActionInvocation arg0) throws Exception {
		if (authEngine.accept(ServletActionContext.getRequest())) {
			return arg0.invoke();
		} else {
			return ResultKeys.FORBIDDEN;
		}
	}

	public Authorization getAuthEngine() {
		return authEngine;
	}

	public void setAuthEngine(Authorization authEngine) {
		this.authEngine = authEngine;
	}

}
